using UnityEngine;
using System.Collections;

public class placarLixo : MonoBehaviour
{
    int id = 27;
    private Vector2 screen;

    void Start()
    {
        this.screen.y = GameObject.Find("Main Camera").GetComponent<Camera>().orthographicSize;
        this.screen.x = this.screen.y * GameObject.Find("Main Camera").GetComponent<Camera>().aspect;

        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");

        Mesh mesh = Quad.Create(this.screen.x * 0.15f, this.screen.y * 0.14f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
        {
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
        };

        this.transform.position = new Vector3(this.screen.x * 0.85f, this.screen.y * 0.9f, -1);
    }

    void Update()
    {
        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
        {
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
           new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
           new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
        };

        if (gameLixo.life == 3)
        {
            id = 27;
        }

        if (gameLixo.life == 2)
        {
            id = 26;
        }

        if (gameLixo.life == 1)
        {
            id = 25;
        }
    }

}
